package segger.vasttrafik;

import java.util.Timer;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;


public class VasttrafikNow {
    private static final Logger logger = Logger.getLogger(VasttrafikNow.class);
    
    private static int ONCE_A_MINUTE = 5*1000; //55*1000;

    private static Timer timer;
    
    private static void initLogging() {
        PropertyConfigurator.configure("conf/log4j.properties");
    }
    
    public static void configure(Configuration conf) {
        initLogging();
        Utils.init();
        
        API.getInstance().setIdentifier(conf.getIdentifier());
        logger.info("VasttrafikNow is configured");
    }
    
    public static void activate(Location location, UpdateListener listener) {
        timer = new Timer();
        timer.schedule(location, 0);
        timer.schedule(new TimeTableTask(location, listener), 0, ONCE_A_MINUTE);
        logger.info("VasttrafikNow is activated");
    }
    
    public static void deactivate() {
        timer.cancel();
        logger.debug("VasttrafikNow is deactivated");
    }
}
